package com.bqy.myokgo.utils;

import com.lzy.okgo.exception.HttpException;
import com.lzy.okgo.model.Response;

import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

/**
 * 熊猫先生
 * 2018/10/22:15:46
 */

public class ErrorUtils {
    public static boolean isError(Response response) {
        Throwable throwable = response.getException();
        if (throwable != null) {
            throwable.printStackTrace();
        }

        if (throwable instanceof IllegalStateException) {
            ToastUtils.show(response.getException().getMessage());
            return true;
        } else {
            if (throwable instanceof UnknownHostException || throwable instanceof ConnectException) {
                ToastUtils.show("网络连接失败,请连接网络");
            } else if (throwable instanceof SocketTimeoutException) {
                ToastUtils.show("网络请求超时");
            } else if (throwable instanceof HttpException) {
                ToastUtils.show("服务器异常,请重试");
            } else {
                ToastUtils.show("网络请求失败,请重试");
            }
            return false;
        }

    }

}
